package com.aizuda.boot.modules.business.back.controller;

import com.aizuda.boot.modules.business.contract.dto.SingleResponse;
import com.aizuda.boot.modules.system.entity.SysDict;
import com.aizuda.boot.modules.system.service.ISysDictService;
import com.aizuda.core.api.ApiResult;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author sangyirong
 * @ClassName BackController
 * @Version 1.0
 * @Date 2025/6/27 16:25
 */
@RestController
@RequestMapping("/backDating")
@Tag(name = "合同倒签", description = "合同倒签治理")
public class BackController {

    private static final String dictCode = "backdating";

    @Resource
    private ISysDictService sysDictService;


    @Operation(summary = "获取合同倒签状态")
    @GetMapping("/getBackStatus")
    public SingleResponse<Integer> getBackStatus() {
        SysDict back = sysDictService.getOne(Wrappers.<SysDict>lambdaQuery()
                .eq(SysDict::getCode, dictCode)
                .last("limit 1"));
        return SingleResponse.of(back.getStatus());
    }

    @Operation(summary = "修改倒签状态")
    @PutMapping("/updateBackStatus")
    public SingleResponse updateBackStatus() {
        SysDict back = sysDictService.getOne(Wrappers.<SysDict>lambdaQuery()
                .eq(SysDict::getCode, dictCode)
                .last("limit 1"));
        back.setStatus(back.getStatus() == 1 ? 0 : 1);
        sysDictService.updateById(back);
        return SingleResponse.success();
    }
}
